package gitbook.ctrl;

import gitbook.User;
import gitbook.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("user")
public class UserLoginCtrl {

    @Autowired
    private UserRepository userRepository;

    @RequestMapping(value = "login",method = RequestMethod.GET)
    public String login(){
        return "/login/login";
    }

    @RequestMapping("me/{username}")
    public String me(@PathVariable String username, Model model){
        User user = userRepository.findByUserName(username);
        model.addAttribute("user",user);
        return "/user/userInfo";
    }

    @RequestMapping("me/signup")
    public String signup(){
        return "user/signup";
    }
}
